﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KerriganDataContract.Session;
using KerriganDataContract;
using System.Diagnostics;
using System.ServiceModel;

namespace KerriganService.DAC
{
    public static class LevelSessionDAC
    {
        public static List<LevelSessionDC> GetListLevelSessions()
        {
            List<LevelSessionDC> list = new List<LevelSessionDC>();

            try
            {
                using (KerriganDBEntities db = new KerriganDBEntities())
                {
                    List<TLevelSession> entities = db.TLevelSessions.ToList();
                    list = LevelSessionDAC.CopyEntitiesToBos(entities);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException(ex.Message);
            }

            return list;
        }

        public static TLevelSession CopyBoToEntity(LevelSessionDC bo)
        {
            TLevelSession entity = new TLevelSession();

            try
            {
                entity.IdLevelSession = bo.IdLevelSessionDC;
                entity.Name = bo.Name;
                entity.MaxApplicant = bo.MaxApplicant;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return entity;
        }


        public static LevelSessionDC CopyEntityToBo(TLevelSession entity)
        {
            LevelSessionDC bo = new LevelSessionDC();

            try
            {
                bo.IdLevelSessionDC = entity.IdLevelSession;
                bo.Name = entity.Name;
                bo.MaxApplicant = entity.MaxApplicant;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return bo;
        }

        public static List<LevelSessionDC> CopyEntitiesToBos(List<TLevelSession> entities)
        {
            List<LevelSessionDC> list = new List<LevelSessionDC>();

            try
            {
                foreach (TLevelSession entity in entities)
                {
                    LevelSessionDC dc = new LevelSessionDC();
                    dc = LevelSessionDAC.CopyEntityToBo(entity);
                    list.Add(dc);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return list;
        }
    }
}